package com.heartworks.mainapplication;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
import android.widget.Toast;

import com.heartworks.mainapplication.ImageAdapter;

public class HWAppActivity extends Activity {
	protected int size = 150;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        
        //Establishes the TO-Do list.
        ListView listView = (ListView) findViewById(R.id.mylist);
        String[] values = new String[] { "Run", "Eat", "Android rocks", "Six Season and a Movie", "420"};
        
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(HWAppActivity.this, R.layout.todolist, R.id.list_content, values);
        
        listView.setAdapter(arrayAdapter);
        
   
       //Fills in the icons 
       final GridView gridView = (GridView) findViewById(R.id.gridView1);
        gridView.setAdapter(new ImageAdapter(this));
        //Needed to change background when TO-DO box is opened.
        final RelativeLayout rootRL = (RelativeLayout) findViewById(R.id.rootRL);
        
        
        //Click listener for the icons.
        gridView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                Toast.makeText(HWAppActivity.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });
        
        //Needed for help-button functionality.
        final Button helpButton = (Button) findViewById(R.id.button1);
        
        helpButton.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
			
				Toast.makeText(HWAppActivity.this, "This button be helpin'", Toast.LENGTH_SHORT).show();
				
			}
		});
        
        //Click listener for the larger/smaller buttons to change the icon size.
        final Button largerButton = (Button) findViewById(R.id.button2);
        
        largerButton.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				size+=25;
				gridView.setAdapter(new ImageAdapter(HWAppActivity.this, size));
			
				Toast.makeText(HWAppActivity.this, "Larger Text", Toast.LENGTH_SHORT).show();
				
			}
		});
        final Button smallerButton = (Button) findViewById(R.id.button3);
        	smallerButton.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				size-=25;
				gridView.setAdapter(new ImageAdapter(HWAppActivity.this, size));
			
				Toast.makeText(HWAppActivity.this, "Smaller Text", Toast.LENGTH_SHORT).show();
				
			}
		});
        
        	//TO-DO functionality. Sliding drawer.
        SlidingDrawer helpDrawer = (SlidingDrawer) findViewById(R.id.slide);
        helpDrawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener(){
			
        //Functionality to hide/change UI elements when the drawer is up  (so they dont appear on top of each other)	
        	public void onDrawerOpened() {
				helpButton.setVisibility(View.INVISIBLE);
				largerButton.setVisibility(View.INVISIBLE);
				smallerButton.setVisibility(View.INVISIBLE);
				rootRL.setBackgroundColor(Color.WHITE);
			}
        });
        helpDrawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
			
			public void onDrawerClosed() {
				helpButton.setVisibility(View.VISIBLE);
				largerButton.setVisibility(View.VISIBLE);
				smallerButton.setVisibility(View.VISIBLE);
				rootRL.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
				
				
			}
		});
    }
}
